﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace LevSTProgramTransform
{
    class TemplateFileSetting
    {
        const string SettingFileDefineStr = "LEV_ST";
        bool isCorrectSettingFileFlag = false;

        string FullFileName;

        XmlDocument _xmlDoc = new XmlDocument();
        public TemplateFileSetting(string XmlFileNamePath)
        {
            //_xmlDoc.Load("TemplateFileSetting.xml");
            _xmlDoc.Load(XmlFileNamePath);
            XmlNode node = _xmlDoc.SelectSingleNode("//ConfigFile");
            string defVal = _xmlDoc.SelectSingleNode("//ConfigFile").Attributes["Def"].Value;
            if (defVal.Equals(SettingFileDefineStr))
            {
                isCorrectSettingFileFlag = true;
                FullFileName = XmlFileNamePath;
                //string fileDirectory = Path.GetDirectoryName(FullFileName);
                //string filename = Path.GetFileName(FullFileName);
            }
        }
        public bool isCorrectSettingFile()
        {
            return isCorrectSettingFileFlag;
        }
        public string getBuildDate()
        {
            if (!isCorrectSettingFileFlag) return string.Empty;
            return _xmlDoc.SelectSingleNode("//ConfigFile/BuildingDate").InnerText;
        }
        public string getBuildTime()
        {
            if (!isCorrectSettingFileFlag) return string.Empty;
            return _xmlDoc.SelectSingleNode("//ConfigFile/BuildingTime").InnerText;
        }
        public string getPrjectName()
        {
            if (!isCorrectSettingFileFlag) return string.Empty;
            return _xmlDoc.SelectSingleNode("//ConfigFile/PrjName").InnerText;
        }        
        public string getPrjectVersion()
        {
            if (!isCorrectSettingFileFlag) return string.Empty;
            return _xmlDoc.SelectSingleNode("//ConfigFile/PrjVer").InnerText;
        }
        public string getHexDirectory()
        {
            if (!isCorrectSettingFileFlag) return string.Empty;
            return Path.GetDirectoryName(FullFileName);
        }        
        public string getPRGName()
        {
            if (!isCorrectSettingFileFlag) return string.Empty;
            return _xmlDoc.SelectSingleNode("//ConfigFile/PRGFile").InnerText;
        }
        public string getRomName()
        {
            if (!isCorrectSettingFileFlag) return string.Empty;
            return _xmlDoc.SelectSingleNode("//ConfigFile/ROMFile").InnerText;
        }
    }//class TemplateFileSetting
}//namespace LevSTProgramTransform
